home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Rexx / AutoDownload.term < prev    next >
Text File  |  1994-07-13  |  5KB  |  176 lines

  1. /*--------------------------------------------------*\
  2. This arexx program uses term to download the contents
  3. of my /scratch/nsd/autodownload/ directory on uxa
  4.  
  5. It gets term going, has term dial uxa (and the phonebook
  6. entry's Login Command is setup to automatically log us
  7. into uxa), sets things up for the download, and has uxa
  8. send all the files in my autodownload directory to my
  9. machine. When the download is finished (or aborted) it
  10. deletes the successfully received files from uxa,
  11. logs out of uxa and the phone dialup server, hangs up,
  12. quits term, and exits.
  13.  
  14. I use it in order to have my Amiga go and download
  15. this stuff at 2 o'clock in the morning while I'm
  16. sleeping and no one is using my phone line, my
  17. computer, the dialup server's modems, etc... .
  18.  
  19. $VER: 1.02 (12.12.93) Nicolas Dade
  20. \*--------------------------------------------------*/
  21.  
  22. /* this port is used by the autologin script to signal us when it is finished and whether it was successfull or not */
  23. portname='autodownload.login.finished'
  24.  
  25. /* get term running */
  26.  termfoundrunning='yes' /* remember whether term was already running or not */
  27.  IF ~show('ports','TERM') THEN DO
  28.    termfoundrunning='no'
  29.    ADDRESS 'COMMAND' 'term:term PORTNAME="TERM" NEW'
  30.    ADDRESS 'COMMAND' 'WaitForPort TERM'
  31.    IF rc>0 THEN DO
  32.      ADDRESS 'COMMAND' 'WaitForPort TERM' /* give it 20 secs to come up */
  33.      IF rc>0 THEN DO
  34.        showerror("Couldn't start term going")
  35.        EXIT 10
  36.      END
  37.    END
  38.    ADDRESS 'TERM' 'DELAY MIC 1' /* wait for term to get settled after its arexx port appears */
  39.  END
  40.  ADDRESS 'TERM'
  41.  
  42. /* dial up uxa --- the autologin script that is tied to the phonebook entry will get us to a shell prompt and then send us a
  43. message */
  44.  IF ~show('L','rexxsupport.library') THEN
  45.    addlib('rexxsupport.library',0,-30,0)
  46.  IF ~show('L','rexxsupport.library') THEN DO
  47.    showerror("Couldn't find rexxsupport.library")
  48.    abort()
  49.  END
  50.  IF ~openport(portname) THEN DO
  51.     showerror("Couldn't create "portname" port")
  52.     abort()
  53.  END
  54.  CLEAR 'FROM dial'
  55.  ADDITEM 'TO dial PHONE Mosberg/uxa/autodownload'
  56.  DIAL
  57. /* wait for dialing to have finished */
  58.  DELAY 'MIC 1'
  59.  
  60. /* this stuff doesn't work for me; x is left unbound
  61.  GETATTR 'term.session.online VAR x'
  62.  SAY 'online is' x /* says: "online is X" */
  63. */
  64.  
  65. /* wait for autologin to have finished (the autologin script will send us a message) */
  66.  DO UNTIL waitpkt(portname)
  67.  END
  68.  msg=getpkt(portname)
  69.  loginresult=getarg(msg,0)
  70.  reply(msg,0) /* allow the login script to proceed (and exit) */
  71.  closeport(portname)
  72.  IF loginresult~=0 THEN DO
  73.    showerror("Autologin script was not successfull")
  74.    abort()
  75.  END
  76.  
  77. /* the login script takes us all the way to a shell prompt on uxa, so we can start issuing commands right away */
  78. /* turn messages off */
  79.  SEND 'mesg n\r'
  80.  IF waitrc('>',"Didn't get prompt back") THEN abort()
  81.  SEND 'biff n\r'
  82.  IF waitrc('>',"Didn't get prompt back") THEN abort()
  83.  
  84. /* move to the autodownload directory */
  85.  SEND 'cd /scratch/nsd/autodownload\r'
  86.  IF waitrc('>',"Didn't get prompt back") THEN abort()
  87.  
  88. /* start the download going */
  89.  SEND 'sz -b *\r'
  90.  RECEIVEFILE 'MODE binary' /* WARNING: THIS HANGS UNTIL IT TIMES OUT IF THERE ARE NO FILES TO SEND */
  91.  DELAY 'MIC 1'
  92.  
  93. /* see if uxa is still there by trying to get a prompt */
  94.  uxaalive='no'
  95.  DO i=1 TO 10 UNTIL uxaalive~='no'
  96.    SEND '\r'
  97.    TIMEOUT 'SEC 10'
  98.    WAIT '>'
  99.    IF rc=0 THEN uxaalive='yes'
  100.  END
  101.  IF uxaalive~='yes' THEN DO
  102.    showerror("uxa seems to no longer be around")
  103.    abort()
  104.  END
  105.  
  106. /* delete files that were completely received */
  107.  filelistfile='t:autodownload.capture'
  108.  CLOSE 'FROM file'
  109.  ADDRESS 'COMMAND' 'delete "'filelistfile'" quiet >nil:'
  110.  CAPTURE 'TO file NAME "'filelistfile'"'
  111.  SEND 'ls -l\r'
  112.  IF waitrc('>',"Didn't get prompt back") THEN abort()
  113.  CLOSE 'FROM file'
  114.  
  115.  OPTIONS RESULTS
  116.  GETATTR 'OBJECT pathprefs FIELD binarydownloadpath'
  117.  dlpath=result
  118.  OPTIONS NO RESULTS
  119.  IF right(dlpath,1)~=':' & right(dlpath,1)~='/' THEN dlpath=dlpath||'/'
  120.  
  121.  IF ~open('filelist',filelistfile,'R') THEN DO
  122.    showerror("Couldn't open "filelistfile", so no files will be deleted")
  123.  END
  124.  ELSE DO
  125.    DO WHILE ~eof('filelist')
  126.      l=readln('filelist')
  127.      IF length(l)>30 & words(l)>4 THEN DO /* filter out non-filelisting lines */
  128.        remotename=word(l,words(l))
  129.        remotelength=word(l,4)
  130.        localname=dlpath||remotename
  131.        IF exists(localname) THEN
  132.          IF remotelength=word(statef(localname),2) THEN DO
  133.            SEND 'rm 'remotename'\r'
  134.            IF waitrc('>',"Didn't get prompt back") THEN abort()
  135.          END
  136.      END
  137.    END
  138.    close('filelist')
  139.    ADDRESS 'COMMAND' 'delete "'filelistfile'" quiet'
  140.  END
  141.  
  142. /* logout and exit */
  143.  SEND 'logout\r'
  144.  IF waitrc('>',"couldn't logout of uxa and get back to the terminal server") THEN abort()
  145.  SEND 'logout\r'
  146.  HANGUP
  147.  IF termfoundrunning='no' THEN
  148.    QUIT 'FORCE'
  149.  EXIT 0
  150.  
  151. /*--------------------------------------*/
  152.  
  153. waitrc: /* (waitstring, errorstring) */
  154.  PARSE ARG waitstring,errorstring
  155.  TIMEOUT 'SEC 10'
  156.  WAIT '"'waitstring'"'
  157.  IF rc=0 THEN DO
  158.    RETURN 0
  159.  END
  160.  ELSE DO
  161.    showerror(errorstring)
  162.    abort()
  163.  END
  164.  
  165. showerror: /* (errorstring) */
  166.  PARSE ARG errorstring
  167.  SAY 'AutoDownload ERROR: 'errorstring
  168.  RETURN 0
  169.  
  170. abort: /* get out of here, leaving a record of what went wrong */
  171.  SAVEAS 'NAME t:autodownload.FAILED.buffer FROM buffer'
  172.  HANGUP
  173.  IF termfoundrunning='no' THEN
  174.    QUIT 'FORCE'
  175.  EXIT 10
  176.